package org.emergency.framework.dao.oa.Impl;

import java.util.List;

import org.emergency.framework.dao.HibernateBaseDao;
import org.emergency.framework.dao.oa.ITbRoleDAO;
import org.emergency.framework.model.TbRole;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

/**
 * 
 * @author Administrator
 *
 */
@Repository("tbRoleDAO")
public class TbRoleDAO extends HibernateBaseDao<TbRole> implements ITbRoleDAO{
	private static final Logger log = LoggerFactory.getLogger(TbRoleDAO.class);

	protected void initDao() {
		// do nothing
	}


	public TbRole findById(java.lang.String id) {
		log.debug("getting TbRole instance with id: " + id);
		try {
			TbRole instance = (TbRole) getHibernateTemplate().get(
					"org.dao.TbRole", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<TbRole> findByExample(TbRole instance) {
		log.debug("finding TbRole instance by example");
		try {
			List<TbRole> results = (List<TbRole>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbRole instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TbRole as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findAll() {
		log.debug("finding all TbRole instances");
		try {
			String queryString = "from TbRole";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbRole merge(TbRole detachedInstance) {
		log.debug("merging TbRole instance");
		try {
			TbRole result = (TbRole) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbRole instance) {
		log.debug("attaching dirty TbRole instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbRole instance) {
		log.debug("attaching clean TbRole instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbRoleDAO getFromApplicationContext(ApplicationContext ctx) {
		return (TbRoleDAO) ctx.getBean("TbRoleDAO");
	}
}